<?php
namespace Mobile\Controller;
use Mobile\Model\goodsModel;
use Mobile\Model\goodstypeModel;

class IndexController extends BaseController {
    
    public $goodsModel;
    public $goodstypeModel;
    
    public function __construct() {
        parent::__construct();
        $this->goodsModel = new goodsModel();
        $this->goodstypeModel = new goodstypeModel();
		
        $BindController = new BindController();
        $BindController->autobind();
		
    }

    /*
     * 获取商品分类
     */
    public function _get_gtype(){
        $data = $this->goodstypeModel->getGoodstypeList();
        $gtypes = array();
        
        foreach($data as $k=>$v){
            $gtypes[$v['gtype_id']] = $v;
        }
        $this->assign('gtype',$gtypes);
        return $data;
    }
    
    
    public function index(){
        
        $title = C("SITE_NAME");
        
        $seo_data = array(
            "title" => $title,
            "description" => "",
            "keywords" => "",
        );
        $this->setSeo($seo_data);
        
        //商品数量统计
        $goods_count = S("goods_count");
        if(!$goods_count){
            $goods_count = A("Goods")->countGoods();//商品
            S("goods_count",$goods_count,1*3600);
        }
        $this->assign('goods_count',$goods_count);
        
        //获取商品列表
        $where = "ischeck=1 AND stock>0 and goods_id!=1";
        $goods_list = $this->goodsModel->getGoodsList($where);
        
        //等级价格
        $grade_id = $this->memberinfo['grade_id'];
        $grade_id = $grade_id ? $grade_id : 0;
        foreach($goods_list as $k=>$v){
            $goods_list[$k]['shop_price'] = $v['grade'.$grade_id.'_price'];
        }
        
        
        $this->assign('datalist',$goods_list);
        $this->assign("grade",$this->memberinfo['grade_id']);
        $share_data = array(
            "title" => C("SITE_NAME"),
        );
        $this->setShare($share_data);
        
        $this->display();
    }
}